package com.project.controller;

import com.project.bean.UserBean;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 登录
     * @param name
     * @param pwd
     * @param request
     * @return
     */
    @RequestMapping("login")
    public String login(String name, String pwd,
                        HttpServletRequest request){
         UserBean user =  userService.login(name, pwd);

         if (user == null){
             return "no";
         }
         request.getSession().setAttribute("loginUser",user);
        return user.getGrade();
    }


    @RequestMapping("getLoginUser")
    public UserBean getLoginUser(HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        return user;
    }
}
